<style scoped>
.operate-log-data-table .footer {
  float: right;
  margin: 12px 0 24px;
}
</style>
<!--  -->
<template>
  <div class="operate-log-data-table" v-loading="loading">
    <DataList :dataTable="dataTable" />
    <div class="footer">
      <PageTurning :page="page" :changePage="changePage" />
    </div>
    <div style="clear:both;"></div>
  </div>
</template>

<script>
import PageTurning from '@/components/common/PageTurning.vue'
import DataList from '@/components/main/user/operate/log/DataList.vue'
export default {
  created () {
    this.resetData()
  },
  props: {
    search: {
      type: Object
    },
    dataTotal: {
      type: Function
    },
    searchPage: {
      type: Function
    },
    pageSize: {
      type: Number
    }
  },
  data () {
    return {
      loading: true,
      page: {
        // 当前页
        page: 1,
        // 一页大小
        size: this.pageSize,
        // 总数
        total: 0
      },
      // 表格显示的数据
      dataTable: []
    }
  },
  watch: {
    pageSize: {
      handler (newValue) {
        this.page.size = newValue
        this.page = JSON.parse(JSON.stringify(this.page))
      },
      deep: true
    }
  },
  methods: {
    // 改变页面
    changePage (page) {
      this.searchPage(page.page)
      this.resetData()
    },
    resetData () {
      // 获取数据
      this.loading = true
      this.$post('/operatelog/loginfos', this.search).then(response => {
        if (response && response.list && response.list.length > 0) {
          this.dataTable = response.list
          this.dataTotal(response.total)
          this.page.total = response.total
        } else {
          this.dataTable = []
          this.dataTotal(0)
          this.page.total = 0
        }
        this.loading = false
      }).then(() => {
        this.page.page = this.search.pageNumber
        this.page = JSON.parse(JSON.stringify(this.page))
      })
    }
  },
  components: {
    PageTurning,
    DataList
  }
}

</script>
